package com.canxin.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.canxin.entity.BinduserEntity;
import com.canxin.entity.ScoreAnalyze;
import com.canxin.entity.ScoreEntity;
import com.canxin.entity.UserFocusEntity;
import com.canxin.service.ChatMenuServiceI;
import com.canxin.service.ScoreAnalyzeServiceI;
import com.canxin.service.ScoreServiceI;
import com.canxin.tools.CountRankCompareDesc;
import com.canxin.tools.DiffRankCompareDesc;
import com.canxin.tools.ListSortUtil;
import com.google.gson.Gson;

import net.sf.json.JSONObject;
import weixin.guanjia.account.service.WeixinAccountServiceI;
import weixin.guanjia.core.util.WeixinUtil;
import weixin.p3.oauth2.pojo.templateMsg.TemplateMsgPojo;
import weixin.p3.oauth2.rule.RemoteWeixinMethod;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
import org.jeecgframework.web.system.service.SystemService;

@Service("scoreAnalyzeService")
@Transactional
public class ScoreAnalyzeServiceImpl extends CommonServiceImpl implements ScoreAnalyzeServiceI {

	@Override
	public Map<String, Object> getWorstSubjectRank(ScoreEntity currentScoreEntity) {
		// TODO Auto-generated method stub
		ArrayList scoreList = new ArrayList();
		scoreList.add(new ScoreAnalyze(currentScoreEntity.getStudentid(),"语文",  Integer.parseInt(currentScoreEntity.getChineserank())));
		scoreList.add(new ScoreAnalyze(currentScoreEntity.getStudentid(),"数学",  Integer.parseInt(currentScoreEntity.getMathrank())));
		scoreList.add(new ScoreAnalyze(currentScoreEntity.getStudentid(),"英语",  Integer.parseInt(currentScoreEntity.getEnglishrank())));
		scoreList.add(new ScoreAnalyze(currentScoreEntity.getStudentid(),"政治",  Integer.parseInt(currentScoreEntity.getPoliticalrank())));
		scoreList.add(new ScoreAnalyze(currentScoreEntity.getStudentid(),"历史",  Integer.parseInt(currentScoreEntity.getHistoryrank())));
		scoreList.add(new ScoreAnalyze(currentScoreEntity.getStudentid(),"地理",  Integer.parseInt(currentScoreEntity.getGeorank())));
	   Collections.sort(scoreList, new DiffRankCompareDesc());
        org.jeecgframework.core.util.LogUtil.info(scoreList.get(0));
        ScoreAnalyze scoreAnalyze = (ScoreAnalyze)scoreList.get(0);
       HashMap map =  new HashMap<String,Object>();
       map.put("diffRank", scoreAnalyze.getDiffRank());
       map.put("subject", scoreAnalyze.getSubject());
		return map;
	}

	@Override
	public Map<String, Object> getBestSubjectRank(ScoreEntity currentScoreEntity, ScoreEntity lastScoreEntity) {
		ArrayList scoreList = new ArrayList();
		scoreList.add(new ScoreAnalyze(currentScoreEntity.getStudentid(),"语文",  Integer.parseInt(currentScoreEntity.getChineserank())-Integer.parseInt(lastScoreEntity.getChineserank())));
		scoreList.add(new ScoreAnalyze(currentScoreEntity.getStudentid(),"数学",  Integer.parseInt(currentScoreEntity.getMathrank())-Integer.parseInt(lastScoreEntity.getMathrank())));
		scoreList.add(new ScoreAnalyze(currentScoreEntity.getStudentid(),"英语",  Integer.parseInt(currentScoreEntity.getEnglishrank())-Integer.parseInt(lastScoreEntity.getEnglishrank())));
		scoreList.add(new ScoreAnalyze(currentScoreEntity.getStudentid(),"政治",  Integer.parseInt(currentScoreEntity.getPoliticalrank())-Integer.parseInt(lastScoreEntity.getPoliticalrank())));
		scoreList.add(new ScoreAnalyze(currentScoreEntity.getStudentid(),"历史",  Integer.parseInt(currentScoreEntity.getHistoryrank())-Integer.parseInt(lastScoreEntity.getHistoryrank())));
		scoreList.add(new ScoreAnalyze(currentScoreEntity.getStudentid(),"地理",  Integer.parseInt(currentScoreEntity.getGeorank())-Integer.parseInt(lastScoreEntity.getGeorank())));
		ListSortUtil sortList = new ListSortUtil();  
        sortList.sort(scoreList, "diffRank", "desc");  
        org.jeecgframework.core.util.LogUtil.info(scoreList.get(0));
        ScoreAnalyze scoreAnalyze = (ScoreAnalyze)scoreList.get(0);
        HashMap map =  new HashMap<String,Object>();
        map.put("diffRank", scoreAnalyze.getDiffRank());
        map.put("subject", scoreAnalyze.getSubject());
 		return map;
	}

	@Override
	public List getTotalRank(String examId,String num) {
		// TODO Auto-generated method stub
		return null;
	}

	
}